package com.example.yoga.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.yoga.entity.Card;
import com.example.yoga.entity.User;
import com.example.yoga.entity.UserCard;
import com.example.yoga.service.ICardService;
import com.example.yoga.service.IUserCardService;
import com.example.yoga.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liwenkai
 * @since 2021-03-10
 */
@RestController
@RequestMapping("/card")
public class CardController {

    @Autowired
    private ICardService cardService;

    @Autowired
    private IUserCardService userCardService;

    @RequestMapping(value="/getMyCard",method = RequestMethod.GET)
    public JsonResult<Card> getMyCard( Integer id) {
        //获取这条用户卡关联数据
        QueryWrapper<UserCard> userCardQueryWrapper = new QueryWrapper<>();
        userCardQueryWrapper.eq("userId",id);
        UserCard one = userCardService.getOne(userCardQueryWrapper);
        //根据数据查询卡的信息
        if (one==null){
            return new JsonResult<>(4000,"暂无数据") ;
        }
        Card card = cardService.getById(one.getCardid());
        return new JsonResult<>(2000,card) ;
    }


}

